/**
 * Moondance UML modeling tool
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.model;

import java.util.ArrayList;
import java.util.List;

/**
 * A container for multiple UML Diagrams. This is the "root" of the model data
 * structure.
 */
public abstract class UMLDiagram extends ModelElement {
	public static final String STATE_DIAGRAM = "State Diagram";

	public static final String CLASS_DIAGRAM = "Class Diagram";

	public static final String UML_DIAGRAM = "UML Diagram";

	/** Property ID to use when a child is added to this diagram. */
	public static final String CHILD_ADDED_PROP = "UMLDiagram.ChildAdded";

	/** Property ID to use when a child is removed from this diagram. */
	public static final String CHILD_REMOVED_PROP = "UMLDiagram.ChildRemoved";

	private static final long serialVersionUID = 1;

	private List<UMLEntity> umlBlocksList = new ArrayList<UMLEntity>();

	private int classIndex = 0;
	private int interfaceIndex = 0;
	private int packageIndex = 0;

	private String diagramName;

	public UMLDiagram(String diagramName) {
		this.diagramName = diagramName;
	}

	/**
	 * Add a shape to this diagram.
	 * 
	 * @param s
	 *            a non-null shape instance
	 * @return true, if the shape was added, false otherwise
	 */
	public boolean addChild(UMLEntity s) {
		if (s != null && umlBlocksList.add(s)) {
			System.out.println("Child added to the diagram");
			firePropertyChange(CHILD_ADDED_PROP, null, s);
			return true;
		}
		return false;
	}

	/**
	 * Return a List of UML blocks in this diagram. The returned List should not
	 * be modified.
	 */
	public List<UMLEntity> getChildren() {
		return umlBlocksList;
	}

	/**
	 * Remove a shape from this diagram.
	 * 
	 * @param s
	 *            a non-null shape instance;
	 * @return true, if the shape was removed, false otherwise
	 */
	public boolean removeChild(UMLEntity s) {
		if (s != null && umlBlocksList.remove(s)) {
			firePropertyChange(CHILD_REMOVED_PROP, null, s);
			return true;
		}
		return false;
	}

	public void setDiagramName(String diagramName) {
		this.diagramName = diagramName;
	}

	public String getDiagramName() {
		return diagramName;
	}

	public int getNewClassIndex() {
		classIndex++;
		return classIndex;
	}

	public int getNewInterfaceIndex() {
		interfaceIndex++;
		return interfaceIndex;
	}

	public int getNewPackageIndex() {
		packageIndex++;
		return packageIndex;
	}

}